from django.urls import re_path
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token

from meiduo_admin.project.views import DetailVisitView
from meiduo_admin.views import image, sku
from meiduo_admin.views.brands import BrandsView, BrandsDetailView
from meiduo_admin.views.goods import GoodsBrandsView, GoodschannelView, GoodsCategoryView, GoodsListView, GoodsView
from meiduo_admin.views.option import SpecSimpleView, SpecOptionView
from meiduo_admin.views.orders import OrderListView, OrderDetailView, OrderStatusView
from meiduo_admin.views.permission import PermissionGroupView, ListPermissionView, PermissionView
from meiduo_admin.views.specs import GoodsSpecsModelViewSet, GoodsSpecsViewSet
from meiduo_admin.views.statistical import UserTotalCountView, UserDailyActiveCountView, UserDailyOrderCountView, \
    UserMonthCountView, UserDayCountView, GoodsDayView
from meiduo_admin.views.users import UserListCreateView, UserListView

urlpatterns=[
    #obtain_jwt_token 自动实现 登录验证 和 生成token
    re_path(r'^authorizations/$',obtain_jwt_token),
    re_path(r'^statistical/total_count/$',UserTotalCountView.as_view()),
    re_path(r'^statistical/day_active/$',UserDailyActiveCountView.as_view()),
    re_path(r'^statistical/day_orders/$',UserDailyOrderCountView.as_view()),
    re_path(r'^statistical/month_increment/$',UserMonthCountView.as_view()),
    re_path(r'^statistical/day_increment/$',UserDayCountView.as_view()),
    re_path(r'^users/?keyword=<搜索内容>&page=<页码>&pagesize=<页容量>$',UserListView.as_view()),
    re_path(r'^users/$',UserListCreateView.as_view()),
    re_path(r'^skus/simple/$', image.SKUView.as_view()),
    re_path(r'^detail/visit/(?P<category_id>\d+)/$', DetailVisitView.as_view()),
    re_path(r'^skus/categories/$', sku.SKUCategoriesView.as_view()),
    re_path(r'^goods/simple/$', sku.GoodsSimpleView.as_view()),
    re_path(r'^statistical/goods_day_views/$', GoodsDayView.as_view()),
    re_path(r'^goods/(?P<pk>\d+)/specs/$', sku.GoodsSpecView.as_view()),
    re_path(r'^goods/brands/simple/$', GoodsBrandsView.as_view()),
    re_path(r'^goods/channel/categories/$', GoodschannelView.as_view()),
    re_path(r'^goods/channel/categories/(?P<pk>\d+)/$', GoodsCategoryView.as_view()),
    re_path(r'^goods/specs/$', GoodsSpecsModelViewSet.as_view()),
    re_path(r'^goods/specs/(?P<pk>\d+)/$', GoodsSpecsViewSet.as_view()),
    re_path(r'^goods/specs/simple/$', SpecSimpleView.as_view()),
    re_path(r'^permission/groups/$', PermissionGroupView.as_view()),
    re_path(r'^goods/brands/$', BrandsView.as_view()),
    re_path(r'^goods/brands/(?P<pk>\d+)/$', BrandsDetailView.as_view()),


]

#创建router实例
router = DefaultRouter()

#注册路由
# router.register(r'goods/specs',GoodsSpecsModelView,basename='specs') # 未实现保存
router.register(r'skus/images',image.ImageView,basename='image')
router.register(r'skus',sku.SKUModelViewSet,basename='skus')
router.register(r'orders',OrderListView,basename='orders')
router.register(r'orders',OrderDetailView,basename='orders1')
router.register(r'orders',OrderStatusView,basename='orders2')
router.register(r'goods',GoodsListView,basename='goods')
router.register(r'goods',GoodsView,basename='goods2')
router.register(r'permission/content_types',ListPermissionView,basename='content_types')
router.register(r'permission/perms',PermissionView,basename='perms')
router.register(r'specs/options',SpecOptionView,basename='options')
# router.register(r'goods/spec',GoodsSpecsViewSet,basename='specs')


#将router生成的路由追加到urlpatterns中
urlpatterns += router.urls